<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="serviceurl" value="${ctx}/modules/sys/user" />
<html>
<head>
<title>修改密码</title>
</head>
<body>
	<div class="container-fluid rap-page-container">
		<div class="row">
			<form class="form-horizontal" name="rap-form-changepwd" id="rap-form-changepwd">
				<div class="control-group">
					<label class="control-label" for="oldpassword">原密码：</label>
					<div class="controls">
						<div class="span12">
							<input type="password" name="oldpassword" id="oldpassword" class="span4" />
						</div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="newpassword">新密码：</label>
					<div class="controls">
						<div class="span12">
							<input type="password" name="newpassword" id="newpassword" class="span4" />
						</div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="newpassword2">确认新密码：</label>
					<div class="controls">
						<div class="span12">
							<input type="password" name="newpassword2" id="newpassword2" class="span4" />
						</div>
					</div>
				</div>

				<div class="form-actions">
					<button id="btn-post" type="button" class="btn btn-mini btn-info">
						<i class="icon-ok bigger-110"></i> 提交
					</button>
					&nbsp; &nbsp; &nbsp;
					<button type="reset" class="btn btn-mini">
						<i class="icon-undo bigger-110"></i> 清除
					</button>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	function changePwd() {
		if (!$('#rap-form-changepwd').valid())
			return false;
		var postData = $("#rap-form-changepwd").serializeArray();

		$.ajax({
			url : '${serviceurl}/changepwd',
			type : 'POST',
			dataType : "json",
			ContentType : "application/json; charset=utf-8",
			data : postData,
			success : function(data) {
				if (data.success) {
					alert("密码修改成功");
				} else {
					alert("密码修改失败，原因：" + data.msg);
				}
			}
		});
	}
	
	$(document).ready(function() {
		$('#btn-post').bind('click', changePwd);
		
		$('#rap-form-changepwd').validate({
			rules : {
				oldpassword : {
					required : true
				},
				newpassword : {
					required : true,
					minlength : 6
				},
				newpassword2 : {
					required : true,
					minlength : 6,
					equalTo : "#newpassword"
				}
			},
			messages : {
				oldpassword : {
					required : "请输入当前用户原始密码"
				},
				newpassword : {
					required : "请输入新密码",
					minlength : "密码不复合安全要求，至少6个字符"
				},
				newpassword2 : {
					required : "请重复输入新密码",
					minlength : "密码不复合安全要求，至少6个字符"
				}
			}
		});
	});
	
	</script>
</body>
</html>